import { message } from 'antd';
import React, { Component } from 'react'
import { queryAllArticles } from '../../api/blog';
import Article from '../../types/Article';
import View from './View';

interface IProps { }
interface IState {
    articles: Array<Article>;
    loading: boolean
}
export default class Home extends Component<IProps, IState> {
    state = {
        loading: true,
        articles: []
    }
    async componentDidMount() {
        //请求所有文章
        const articles: Article[] | null = await queryAllArticles();
        if (articles && articles.length === 0) {
            message.warn('文章为空');
        };
        if (!!articles) {
            this.setState({
                loading: false,
                articles: articles
            })
        }
    }
    render() {
        const { loading, articles } = this.state;
        return (
            <div>
                <View articles={articles} loading={loading} />
            </div>
        )
    }
}
